import java.awt.Graphics;
import java.util.HashMap;
import java.util.Vector;

import me.w70.bot.Bot;
import me.w70.bot.scripting.GUIBuilder;
import me.w70.bot.scripting.Script;
import me.w70.bot.wrappers.RSObject;

public class SpookyPowerMiner extends Script {

	int[] copperAndTinRocks = new int[] { 11935, 11934, 11933, 11938, 11936,
			11963, 11937, 9709, 9708, 9710, 11960, 11962, 11961, 11958, 31080,
			31082, 31079, 31078, 31077 };

	int[] copperRocks = new int[] { 11938, 11936, 11963, 11937, 9709, 9708,
			9710, 11960, 11962, 11961, 31080, 31082 };

	int[] tinRocks = new int[] { 11935, 11934, 11933, 11959, 11957, 11959,
			11958, 9714, 9716, 31079, 31077, 31078 };

	int[] goldAndSilverRocks = new int[] { 37312, 37310, 37305, 37304, 37306,
			2311, 9722, 9720, 11950, 9720, 9722, 37313, 9714, 9716, 9713,
			11950, 11949, 11948, 15505, 15503, 11185, 11184, 11183, 31065,
			31066 };

	int[] goldRocks = new int[] { 37312, 37310, 9722, 9720, 15505, 15503,
			11185, 11184, 11183, 9720, 9722, 37313, 31065, 31066 };

	int[] silverRocks = new int[] { 37305, 37304, 37306, 2311, 9714, 9716,
			9713, 11950, 11949, 11948, 11950 };

	int[] mithrilAndAddyRocks = new int[] { 11942, 11944, 11939, 11941, 32438,
			32439, 32435, 32436, 31086, 31088, 31083 };

	int[] mithrilRocks = new int[] { 11942, 11944, 11943, 32438, 32439, 31086,
			31088 };

	int[] addyRocks = new int[] { 11939, 11941, 32435, 32436, 11940, 31083,
			31084, 31085, 31083 };

	int[] clayAndCoalRocks = new int[] { 9711, 9713, 11930, 11931, 15503,
			15504, 15505, 11930, 11932, 11963, 11964, 2096, 2097, 14850, 14851,
			14852, 32426, 32426, 31068, 31069, 31070, 31062, 31063, 31068 };

	int[] clayRocks = new int[] { 9711, 9713, 15503, 15504, 15505, 31062, 31063 };

	int[] coalRocks = new int[] { 11930, 11931, 11932, 11930, 11963, 11964,
			2096, 2097, 14850, 14851, 14852, 32426, 32426, 31068, 31069, 31070,
			31068 };

	int[] sandstoneAnGraniteRocks = new int[] { 10946, 10947 };

	int[] sandstoneRocks = new int[] { 10946 };

	int[] graniteRocks = new int[] { 10947 };

	int[] runiteRocks = new int[] { 451 };

	int[] ironRocks = { 2093, 2093, 2092, 9717, 9719, 9717, 9718, 11956, 11955,
			11954, 37307, 37309, 31072, 31073, 31071 };

	int[] allRocks = new int[] { 11935, 11934, 11933, 11930, 11932, 31086,
			37307, 15503, 31083, 31072, 31088, 31065, 31066, 31073, 31068,
			15504, 31078, 15505, 37309, 31071, 2092, 31062, 31063, 31080,
			31079, 31082, 11963, 2096, 11950, 32435, 32436, 32426, 32438,
			32439, 31068, 31069, 31070, 32427, 14850, 14851, 14852, 2097,
			11964, 11931, 11185, 11184, 11963, 11930, 11959, 11183, 11957,
			11959, 11942, 11943, 2093, 11960, 11958, 11961, 11962, 11954,
			11950, 11956, 11955, 11949, 11948, 15505, 15503, 2093, 9717, 11959,
			11957, 11959, 9719, 9717, 9718, 9711, 9713, 11944, 11939, 11941,
			11938, 11936, 11963, 11937, 9709, 9708, 9710, 37312, 37310, 37305,
			37304, 37306, 2311, 9722, 9720, 9714, 9716, 9713 };

	int[] rocks = new int[] {};

	int[] ores = new int[] { 449, 436, 444, 440, 447, 451, 442, 438, 434, 453,
			6977, 6971, 6973, 6975, 6981, 6979, 6983 };

	int tries = 0;

	int maxtries = 10;

	public int miningAnimation = 625;

	public SpookyPowerMiner() {
	}

	@Override
	public void draw(Graphics g) {

	}

	@Override
	public String getScriptAuthor() {
		return "spooky";
	}

	@Override
	public String getScriptCategory() {
		return "Mining";
	}

	@Override
	public String getScriptName() {
		return "Spooky Power Miner";
	}

	public boolean atRock() {

		RSObject rock = getNearestObjectByID(rocks);
		if (rock == null)
			return false;

		return tileOnScreen(rock.getLocation());
	}

	@Override
	public boolean onLoad() {
		usesGUI = true;
		Vector rocks = new Vector();
		rocks.add("Clay");
		rocks.add("Granite");
		rocks.add("Sandstone");
		rocks.add("Sandstone & Granite");
		rocks.add("Clay & Coal");
		rocks.add("Copper & Tin");
		rocks.add("Copper");
		rocks.add("Tin");
		rocks.add("Iron");
		rocks.add("Coal");
		rocks.add("Gold & Silver");
		rocks.add("Gold");
		rocks.add("Silver");
		rocks.add("Mithril");
		rocks.add("Adamant");
		rocks.add("Mithril & Adamant");
		rocks.add("Runite");
		rocks.add("All Available");
		gui.addSelection("Select rock:", "rock", rocks);
		gui.display();
		return true;
	}

	public void afterGUI(HashMap args) {
		System.out.println(args.get("rock"));
		if (args.get("rock").equals("Clay")) {
			rocks = clayRocks;
		}
		if (args.get("rock").equals("Granite")) {
			rocks = graniteRocks;
		}
		if (args.get("rock").equals("Sandstone")) {
			rocks = sandstoneRocks;
		}
		if (args.get("rock").equals("Sandstone & Granite")) {
			rocks = sandstoneAnGraniteRocks;
		}
		if (args.get("rock").equals("Clay & Coal")) {
			rocks = clayAndCoalRocks;
		}
		if (args.get("rock").equals("Copper & Tin")) {
			rocks = copperAndTinRocks;
		}
		if (args.get("rock").equals("Copper")) {
			rocks = copperRocks;
		}
		if (args.get("rock").equals("Tin")) {
			rocks = tinRocks;
		}
		if (args.get("rock").equals("Iron")) {
			rocks = ironRocks;
		}
		if (args.get("rock").equals("Coal")) {
			rocks = coalRocks;
		}
		if (args.get("rock").equals("Gold & Silver")) {
			rocks = goldAndSilverRocks;
		}
		if (args.get("rock").equals("Gold")) {
			rocks = goldRocks;
		}
		if (args.get("rock").equals("Silver")) {
			rocks = silverRocks;
		}
		if (args.get("rock").equals("Mithril")) {
			rocks = mithrilRocks;
		}
		if (args.get("rock").equals("Adamant")) {
			rocks = addyRocks;
		}
		if (args.get("rock").equals("Mithril & Adamant")) {
			rocks = mithrilAndAddyRocks;
		}
		if (args.get("rock").equals("Runite")) {
			rocks = runiteRocks;
		}
		if (args.get("rock").equals("All Available")) {
			rocks = allRocks;
		}
	}

	public boolean mineRock() {
		RSObject rock = getNearestObjectByID(rocks);
		if (rock == null)
			return false;

		return atObject(rock, "Mine");
	}

	int distance = 0;

	@Override
	public int loop() {

		if (getMyPlayer().isMoving()
				|| getMyPlayer().getAnimation() == miningAnimation) {
			return random(800, 1600);
		}

		if (isInventoryFull()) {
			if (dropItems(ores)) {
				return random(5000, 10000);
			}
		} else {
			if (atRock()) {
				if (mineRock()) {
					return random(800, 1000);

				}
			} else {
				wait(random(800, 1000));
				tries++;
				if (tries == maxtries) {
					Bot.addWarning(this, "Could not find any rocks");
					Bot.stopScripts();
				}
			}
		}
		return 100;
	}

	@Override
	public String getScriptDescription() {
		return "Global Powerminer";
	}

}
